<template>
  <div>
    <el-button @click="submit" type="success" size="medium">Save</el-button>
    <div class="mt30 ft18"><i class="el-icon-star-on"></i>WeChat资料</div>
    <div class="pw100 flex_aj column">
      <r-list :ListRows="ListRows" :ListData="ListData"></r-list>
    </div>
    <div class="mt30 ft18"><i class="el-icon-star-on"></i>Alipay资料</div>
    <div class="pw100 flex_aj column">
      <r-list :ListRows="ListRowsAli" :ListData="ListDataAli"></r-list>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      id: "",
      ListRows: [
        [
          {
            label: "WeChatAPPID",
            prop: "wxAppId",
            type: "input"
          },
          {
            label: "WeChat商户Name",
            prop: "wxMchName",
            type: "input"
          },
          {
            label: "WeChat商户ID",
            prop: "wxMchId",
            type: "input"
          },
          {
            label: "WeChat商户KEY",
            prop: "wxMchKey",
            type: "input"
          },
          {
            label: "WeChat商户密码",
            prop: "wxSecrect",
            type: "input"
          },
          {
            label: "WeChat退款证书",
            prop: "wxCertPath",
            type: "input",
            isDisabled: () => {
              return true;
            },
            upload: {
              action: process.env.VUE_APP_URL + "api/file/uploadCert",
              success: res => {
                this.ListData.wxCertPath = res.data.imgPath;
              },
              handleExceed: () => {
                this.$message.warning(
                  `Current限制选择 1 个文件，本次选择了 ${
                    files.length
                  } 个文件，共选择了 ${files.length + fileList.length} 个文件`
                );
              }
            }
          },
          {
            label: "Payment分ID",
            prop: "serviceId",
            type: "input"
          },
          {
            label: "公众号消息模版ID",
            prop: "msgTemplateId",
            type: "input"
          },
          {
            label: "WeChat私钥证书路径",
            prop: "wxPemkeyPath",
            type: "input",
            isDisabled: () => {
              return true;
            },
            upload: {
              action: process.env.VUE_APP_URL + "api/file/uploadCert",
              success: res => {
                this.ListData.wxPemkeyPath = res.data.imgPath;
              },
              handleExceed: () => {
                this.$message.warning(
                  `Current限制选择 1 个文件，本次选择了 ${
                    files.length
                  } 个文件，共选择了 ${files.length + fileList.length} 个文件`
                );
              }
            }
          },
          {
            label: "商户API证书序列号",
            prop: "wxSerialNo",
            type: "input"
          }
        ]
      ],
      ListData: {
        wxAppId: "",
        wxMchName: "",
        wxMchId: "",
        wxMchKey: "",
        wxSecrect: "",
        wxCertPath: "",
        serviceId: "",
        msgTemplateId: "",
        wxPemkeyPath: "",
        wxSerialNo: ""
      },
      ListRowsAli: [
        [
          {
            label: "AlipayAPPID",
            prop: "aliAppId",
            type: "input"
          },
          // {
          //     label: 'sellerlD',
          //     prop: 'weixinName',
          //   type:'input'
          // },
          {
            label: "私钥key",
            prop: "privateKey",
            type: "input"
          },
          {
            label: "公钥key",
            prop: "publicKey",
            type: "input"
          }
        ]
      ],
      ListDataAli: {
        aliAppId: "",
        privateKey: "",
        publicKey: ""
      }
    };
  },
  components: {},
  computed: {},
  mounted() {
    this.getData();
  },
  methods: {
    async submit() {
      if (this.id) {
        var res = await this.apis.pay_updata({
          id: this.id,
          wxMchName: this.ListData.wxMchName,
          wxMchId: this.ListData.wxMchId,
          wxAppId: this.ListData.wxAppId,
          wxMchKey: this.ListData.wxMchKey,
          wxSecrect: this.ListData.wxSecrect,
          wxCertPath: this.ListData.wxCertPath,
          serviceId: this.ListData.serviceId,
          msgTemplateId: this.ListData.msgTemplateId,
          wxPemkeyPath: this.ListData.wxPemkeyPath,
          wxSerialNo: this.ListData.wxSerialNo,

          aliAppId: this.ListDataAli.aliAppId,
          privateKey: this.ListDataAli.privateKey,
          publicKey: this.ListDataAli.publicKey
        });
      } else {
        var res = await this.apis.pay_add({
          wxMchName: this.ListData.wxMchName,
          wxMchId: this.ListData.wxMchId,
          wxAppId: this.ListData.wxAppId,
          wxMchKey: this.ListData.wxMchKey,
          wxSecrect: this.ListData.wxSecrect,
          wxCertPath: this.ListData.wxCertPath,
          serviceId: this.ListData.serviceId,
          msgTemplateId: this.ListData.msgTemplateId,
          wxPemkeyPath: this.ListData.wxPemkeyPath,
          wxSerialNo: this.ListData.wxSerialNo,

          aliAppId: this.ListDataAli.aliAppId,
          privateKey: this.ListDataAli.privateKey,
          publicKey: this.ListDataAli.publicKey
        });
      }

      this.$message({
        message: "Operations Success",
        type: "success"
      });
    },
    async getData() {
      var res = await this.apis.operatorPayInfo({
        id: this.$route.query.id
      });

      if (res.data) {
        var data = res.data || {};
        this.id = data.id;
        for (var key in data) {
          for (var key2 in this.ListData) {
            if (key == key2) {
              this.ListData[key2] = data[key];
            }
          }

          for (var key3 in this.ListDataAli) {
            if (key == key3) {
              this.ListDataAli[key3] = data[key];
            }
          }
        }
      }
    },
    subEditPassword() {},
    showMsgID() {}
  }
};
</script>
<style scoped lang="scss"></style>
